package chapter12;

import java.io.IOException;
import java.io.PrintStream;
import java.net.Socket;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author lzy
 * @create 2018-03-23 下午2:50
 */
public class TcpClient {
    public static void main(String[] args) {
        try (Socket socket = new Socket("192.168.100.66", 6001);
             Scanner input = new Scanner(socket.getInputStream());
             PrintStream output = new PrintStream(socket.getOutputStream())) {
            input.useDelimiter("\n");
            for (int i = 0; i < 10; i++) {
                output.println(i);
                if (input.hasNext()) {
                    System.out.println("[receive from server]:" + input.next());
                }
            }
            output.println("quit");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
